package SendFile.com;



import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import XuLy.*;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.view.View;
import android.view.View.*;
public class SendFileActivity extends Activity {
	
	EditText TenFile ;
	Button DocFile;
	Button SendFileTCP;
	Button SendFileUDP;
	Button Dong;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TenFile = (EditText)findViewById(R.id.et_TenFile);
        SendFileTCP = (Button)findViewById(R.id.btn_SendTCP);
        SendFileUDP = (Button)findViewById(R.id.btn_SendUDP);
        Dong = (Button)findViewById(R.id.btn_DongFile);
        SendFileTCP.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				SendFileTCP u = new SendFileTCP();
				String a = u.SendUsingTCP();//u.KetNoi("Như Cùi Bắp");
				Toast.makeText(getBaseContext(), a, Toast.LENGTH_SHORT).show();
				
			}
		});
        
        DocFile = (Button)findViewById(R.id.btn_DocFile);
        DocFile.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				try {
					File myfile = new File("/sdcard/bluetooth/b.ppt");
					FileInputStream fIn = new FileInputStream(myfile);
					BufferedReader myreader = new BufferedReader(new InputStreamReader(fIn));
					String aData = "";
					String aBuffer ="";
					while((aData = myreader.readLine() )!=null)
					{
						aBuffer += aData + "\n";
						
					}
					TenFile.setText(aBuffer);
					myreader.close();
					Toast.makeText(getBaseContext(), "Done reading SD 'nhu.txt'", Toast.LENGTH_SHORT).show();
				} catch (Exception e) {
					// TODO: handle exception
					Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
				}
				
			}
		});
        
        SendFileUDP.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				SendFileUDP u = new SendFileUDP();
 				String a = u.SendUsingUDP();
				Toast.makeText(getBaseContext(), a, Toast.LENGTH_SHORT).show();
			}
		});
        
        Dong.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish(); 
			}
		});
    }
}